import { promises as fs } from 'fs';
import path from 'path';

export async function findJSFiles(dirPath, fileNamePattern = /\.js$/) {
  const entries = await fs.readdir(dirPath, { withFileTypes: true });
  const jsFiles = [];
  
  for (const entry of entries) {
    const fullPath = path.join(dirPath, entry.name);
    
    if (entry.isDirectory()) {
      const subDirFiles = await findJSFiles(fullPath, fileNamePattern);
      jsFiles.push(...subDirFiles);
    } else if (entry.isFile() && fileNamePattern.test(entry.name)) {
      jsFiles.push(fullPath);
    }
  }
  
  return jsFiles;
}